﻿using EasyShop.GoodsService.App.Interface;
using EasyShop.GoodsService.Domain;
using EasyShop.GoodsService.Response;
using Infrastructure;
using System.Collections.Generic;
using System.Linq;

namespace EasyShop.GoodsService.App
{
    public class GoodsApp:IGoodsApp
    {
        private readonly MySqlDBContext _mySqlDBContext;
        public GoodsApp(MySqlDBContext mySqlDBContext)
        {
            _mySqlDBContext = mySqlDBContext;
        }
        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <returns></returns>
        public List<GoodsListView> GetList()
        {
            //业务逻辑均非常简单，只为搭建微服务框架，不做分页，查询等功能
            var goods = _mySqlDBContext.Goods.ToList();
            var result = new List<GoodsListView>();
            foreach (var item in goods)
            {
                var goodsListView = item.MapTo<GoodsListView>();
                result.Add(goodsListView);
            }
            return result;
        }
    }
}
